// pages/gateWay/gateWay.js
const app = getApp();
const api = require('../../apis/request.js');
Page({


  /**
   * 页面的初始数据
   */
  data: {
    currentIndex: 0,
    indicatorDots: true,
    src:"",
    title_:true,
    width_: wx.getSystemInfoSync().windowHeight -100,
    height_: wx.getSystemInfoSync().windowHeight - 40,
  },
  methods: {
    // devices_gserial(a) {
    //   console.log(a, 123)
    // }
    // get_inter_id() {
    //   console.log('11111111111111111111')
    // }
  },
  //swiper切换时会调用
  pagechange: function (e) {
    if ("touch" === e.detail.source) {
      let currentPageIndex = this.data.currentIndex;
      currentPageIndex = (currentPageIndex + 1) % 2;
      this.setData({
        currentIndex: currentPageIndex
      });
    }
  },
  //用户点击tab时调用
  titleClick: function (e) {
    // console.log(this)
    this.setData({
      title_:!this.data.title_
    })
    console.log(this.data.currentIndex)
    let currentPageIndex =
      this.setData({
        //拿到当前索引并动态改变
        currentIndex: e.currentTarget.dataset.idx
      });
  },
  get_inter_id(a) {
    // console.log(a)
    // device_
    this.selectComponent("#device_").device_hq();
  },
  dingshi(options) {
    var _this = this;

      var data = JSON.parse(unescape(options.data));
      // console.log(data,321321321231321321)

      api.listCameraByGserial(data.serial, function (res) {
        var data = res.data;
        // console.log(JSON.stringify(data));
        // _this.setData({url:data.datas[0].playUrl});
        var cameraList = data.datas;
        _this.setData({ cameraList: cameraList });
      });
    

        api.listCollectorByGserial(data.serial, function (res) {
          var data = res.data;

          _this.setData({ collectorList: data.datas });
        });

        api.listRegionByGserial(data.serial, function (res) {
          var data = res.data;
          console.log(data.datas[0])
          var arr = [data.datas[0]]
          _this.setData({ regionList: data.datas, regionList_0: arr });

        });
    },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // console.log( 321321321231321321)
  
    var _this = this;
    var winWidth = wx.getSystemInfoSync().windowWidth;
    var winHeight = wx.getSystemInfoSync().windowHeight;
    var heightPx = winHeight - 588 / 750 * winWidth;
    console.log("heightPx = " +heightPx)
    _this.setData({
      contentHeight: heightPx
    });
    this.dingshi(options)
    // console.log(_this.selectComponent("#device_"), '我是onReady')   

    // var data = unescape(JSON.stringify(options.data));
    // setInterval(() => {
    //   _this.dingshi(options)
    // }, 5000)
  //  fn()
    // _this.get_inter_id()
    // wx.request({

    //   url: app.globalData.URL + "/collector/listByGSerial/" + data.serial,
    //   header: {
    //     "Accept": "application/json",
    //     "Content-Type": "application/json",
    //     "token": app.globalData.token
    //   },
    //   method: "GET",
    //   // data: { username: this.data.username, password: md5.hexMD5(this.data.password) },
    //   complete: function (res) {
    //     var data = res.data;
    //     // console.log(JSON.stringify(data));
    //     // _this.setData({url:data.datas[0].playUrl});
    //     // var collectorList = data.datas;
    //     // console.log("collectorList = "+JSON.stringify(collectorList));
    //     // for (var index in collectorList){
    //     //   console.log(collectorList[index].gSerial + "\n" + collectorList[index].addr);
    //     // }
    //     _this.setData({ collectorList: data.datas });
    //   }
    // });

   
  

    // wx.request({

    //   url: app.globalData.URL + "/regionInfo/list/" + data.serial,
    //   header: {
    //     "Accept": "application/json",
    //     "Content-Type": "application/json",
    //     "token": app.globalData.token
    //   },
    //   method: "GET",
    //   // data: { username: this.data.username, password: md5.hexMD5(this.data.password) },
    //   complete: function (res) {
    //     var data = res.data;
    //     // console.log("regionInfo:"+JSON.stringify(data));
    //     // _this.setData({url:data.datas[0].playUrl});
    //     // var collectorList = data.datas;
    //     // console.log("collectorList = "+JSON.stringify(collectorList));
    //     // for (var index in collectorList){
    //     //   console.log(collectorList[index].gSerial + "\n" + collectorList[index].addr);
    //     // }
    //     _this.setData({ regionList: data.datas });
    //   }
    // });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    // this.selectComponent("#device_").device_hq();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // this.selectComponent("#device_").device_hq();

    // console.log('我执行了，显示的后')
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    // clearInterval(0)
  // wx.getStorage({
  //     key: 'inter_id',
  //     success(res) {
  //       console.log(res.data, '我执行了')
  //       clearInterval(res.data)
  //     }
  //   })
    // console.log('我执行了')
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  setting: function (e) {
    var _this = this;
    if (_this.data.regionList == undefined) {
      wx.showToast({
        title: '没有设备信息,无法进行高级设置',
      });
      return;
    }
    wx.navigateTo({
      url: '../setting/setting?data=' + escape(JSON.stringify(_this.data.regionList))
    });
  }
})